package com.dican.portal.pedidos;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dican.portal.beans.Produto;
import com.dican.portal.beans.Representante;

public class rmProd extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public rmProd() {
        super();

    }
	@SuppressWarnings("unchecked")
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		if((Representante)session.getAttribute("rep")==null)
			response.sendRedirect("logout");
		else{
			List<Produto> listaProd;
			if(session.getAttribute("listaProd")==null)
				listaProd = new ArrayList<Produto>();
			else
				listaProd = (List<Produto>)session.getAttribute("listaProd");
			listaProd.remove(Integer.parseInt(request.getParameter("txt")));
			session.setAttribute("listaProd", listaProd); 
			RequestDispatcher view = request.getRequestDispatcher("digitarpedido.jsp");
			view.forward(request, response);
		}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}
}
